package com.yellowpage.nsp.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.nsp.data.NspServer;
import com.yellowpage.nsp.dao.NspServerDao;

public class NspServerServiceImpl extends BaseServiceImpl implements NspServerService {
	  private NspServerDao nspServerDao;
	
	  public void setNspServerDao(NspServerDao nspServerDao) {
		  this.nspServerDao = nspServerDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public NspServer getNspServer(Long id){
	      return nspServerDao.get(id);
	  }
	  
    public List<NspServer> getAllNspServer(){
        return nspServerDao.getAll();
    }
    
    public List<Map> queryNspServerByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.SERVER_ID , a.IP , a.OS , a.USER_PASSWORD , a.LOG_DIR , a.CREATE_USER , a.CREATE_TIME , a.LAST_UPDATE_USER , a.LAST_UPDATE_TIME , a.NOTE , a.NAME , a.TYPE , a.STATUS , a.USER_NAME    FROM NSP_SERVER a WHERE 1=1 ")
				    			.addCondition(" and SERVER_ID = :serverId ")
							    			.addCondition(" and IP = :ip ")
							    			.addCondition(" and OS = :os ")
							    			.addCondition(" and USER_PASSWORD = :userPassword ")
							    			.addCondition(" and LOG_DIR = :logDir ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    			.addCondition(" and NOTE = :note ")
							    			.addCondition(" and NAME like :name ")
							    			.addCondition(" and TYPE = :type ")
							    			.addCondition(" and STATUS = :status ")
							    			.addCondition(" and USER_NAME = :userName ")
							    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveNspServer(NspServer nspServer){
        nspServerDao.save(nspServer);
    }
    
	  public void updateNspServer(NspServer nspServer){
	      nspServerDao.update(nspServer);
	  }
	  
	  public void delete(List deleteList){
	      nspServerDao.remove(deleteList);
	  }
	  
	  public List<Map> getServer(String serverIp){
		  return nspServerDao.query("select * from NSP_SERVER where IP='"+serverIp+"' AND STATUS!=1", null);
		    
	  }
	 
	
}	